<?php
if($_POST)
{
$Page = $_POST['page'];	
$formnumber=$_POST['formnumber'];
$studentname=$_POST['studentname'];
$fathername=$_POST['fathername'];
$gender=$_POST['gender'];
$Per_Page = 5;
$Prev_Page = $Page - 1;
$Next_Page = $Page + 1;
$Page_Start = (($Per_Page * $Page) -$Per_Page);

include('connection.php');
$sql = "SELECT * FROM  `student information` ";

$whereClause = " WHERE 1=1 ";
if(!empty($formnumber)) {
    $whereClause .= " AND form_number='$formnumber' ";
}
if(!empty($studentname)) {
    $whereClause .= " AND full_name='$studentname' ";
}
if(!empty($gender)) {
    $whereClause .= " AND gender='$gender' ";
}
if(!empty($state)) {
    $whereClause .= " AND father_name='$fathername' ";
}

$sql .= $whereClause;
$result = mysql_query($sql,$con);
$Num_Rows = mysql_num_rows($result);


if ($Num_Rows <= $Per_Page) {
    $Num_Pages = 1;
} elseif (($Num_Rows % $Per_Page) == 0) {
    $Num_Pages = ($Num_Rows / $Per_Page) ;
} else {
    $Num_Pages = ($Num_Rows / $Per_Page) + 1;
    $Num_Pages = (int) $Num_Pages;
}
$sql .=" LIMIT $Page_Start , $Per_Page";
$result  = mysql_query($sql) or trigger_error(mysql_error());


while($row = mysql_fetch_array($result))
{ echo "<div class='' '>"; 
 echo "<div style=''>";
  echo"<img src='studentprofileimage/".$row['photo']."' style='height:70px; width:50px; '  >";
  echo "<div> Student ID-".$row['student_id']."</div>";
echo "</div>";
	echo "<div  style=''>";   
echo "<table>";
	echo "<tr><td>Name:</td><td>".$row['full_name'] .  "</td>";
	
echo "</table>";


echo"</div>"; 
echo "<a href='profile.php?id=$row[student_id]' class='moredetail'>More Details</a> ";


	echo"</div>";
}

$Prev_Page = $Page - 1;
$Next_Page = $Page + 1;
if($Prev_Page !=0 )
{
	 echo " <input type='button' class='searchbutton'  value='Prev'  onclick=search('$Prev_Page')> ";
	}
	
for ($i=1; $i <= $Num_Pages; $i++) {
    if ($i != $Page) {
		
        echo " <input type='button'  class='searchbutton' value='$i' onclick=search('$i')> ";
    } else {
		
        echo "<span class='searchbutton' ><big> <b> $i</b> </big></span>"; 
    }
}
if($Page !=$Num_Pages)
{
	 echo " <input type='button'  value='Next' class='searchbutton' onclick=search('$Next_Page')> ";
	}
	


mysql_close($con);
}
?>